package com.example.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shopapp.R;
import com.example.viewmodel.Channel;
import com.example.viewmodel.LeftMenu;

import java.util.List;

public class LeftMenuAdapter extends BaseAdapter {

    private Context ctx;
    private List<LeftMenu> leftMenus;
    public LeftMenuAdapter(Context ctx,List<LeftMenu> leftMenus) {
        this.ctx=ctx;
        this.leftMenus=leftMenus;
    }

    @Override
    public int getCount() {
        return this.leftMenus.size();
    }

    @Override
    public Object getItem(int position) {
        return this.leftMenus.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            convertView= LayoutInflater.from(this.ctx).inflate(R.layout.catalog_left_item,null);
            viewHolder=new ViewHolder();
            viewHolder.catalog_left_item_line=convertView.findViewById(R.id.catalog_left_item_line);
            viewHolder.catalog_left_item_text=convertView.findViewById(R.id.catalog_left_item_text);
            convertView.setTag(viewHolder);
        }else {
            viewHolder=(ViewHolder) convertView.getTag();
        }
        if (this.leftMenus.get(position).getChecked()){
            //显示红色
            viewHolder.catalog_left_item_line.setVisibility(View.VISIBLE);
        }else {
            //不显示红色
            viewHolder.catalog_left_item_line.setVisibility(View.INVISIBLE);
        }
        viewHolder.catalog_left_item_text.setText(this.leftMenus.get(position).getName());
        return convertView;
    }

    static class ViewHolder{
        TextView catalog_left_item_line;
        TextView catalog_left_item_text;
    }
}
